﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:hsc_task_info
	/// </summary>
	public partial class hsc_task_info
	{
		public hsc_task_info()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from hsc_task_info");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.hsc_task_info model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into hsc_task_info(");
			strSql.Append("taskid,infotype,infobytype1,infotypename,infoid,infofv1,infofv2,infofv3,infofv4,infonv4,infonv3,infonv2,infonv1,infodt4,infodt3,infodt2,infodt1,infoimg1,infoimg2,infoimg3,infoimg4,dataadduserid,datadepid,databranchid,datadepname,dataaddusername,databranchname,dataaddtime)");
			strSql.Append(" values (");
			strSql.Append("@taskid,@infotype,@infobytype1,@infotypename,@infoid,@infofv1,@infofv2,@infofv3,@infofv4,@infonv4,@infonv3,@infonv2,@infonv1,@infodt4,@infodt3,@infodt2,@infodt1,@infoimg1,@infoimg2,@infoimg3,@infoimg4,@dataadduserid,@datadepid,@databranchid,@datadepname,@dataaddusername,@databranchname,@dataaddtime)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@taskid", MySqlDbType.Int64,20),
					new MySqlParameter("@infotype", MySqlDbType.Int32,11),
					new MySqlParameter("@infobytype1", MySqlDbType.Int32,11),
					new MySqlParameter("@infotypename", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoid", MySqlDbType.Int64,20),
					new MySqlParameter("@infofv1", MySqlDbType.VarChar,100),
					new MySqlParameter("@infofv2", MySqlDbType.VarChar,100),
					new MySqlParameter("@infofv3", MySqlDbType.VarChar,100),
					new MySqlParameter("@infofv4", MySqlDbType.VarChar,100),
					new MySqlParameter("@infonv4", MySqlDbType.Double),
					new MySqlParameter("@infonv3", MySqlDbType.Double),
					new MySqlParameter("@infonv2", MySqlDbType.Double),
					new MySqlParameter("@infonv1", MySqlDbType.Double),
					new MySqlParameter("@infodt4", MySqlDbType.DateTime),
					new MySqlParameter("@infodt3", MySqlDbType.DateTime),
					new MySqlParameter("@infodt2", MySqlDbType.DateTime),
					new MySqlParameter("@infodt1", MySqlDbType.DateTime),
					new MySqlParameter("@infoimg1", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoimg2", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoimg3", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoimg4", MySqlDbType.VarChar,50),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime)};
			parameters[0].Value = model.taskid;
			parameters[1].Value = model.infotype;
			parameters[2].Value = model.infobytype1;
			parameters[3].Value = model.infotypename;
			parameters[4].Value = model.infoid;
			parameters[5].Value = model.infofv1;
			parameters[6].Value = model.infofv2;
			parameters[7].Value = model.infofv3;
			parameters[8].Value = model.infofv4;
			parameters[9].Value = model.infonv4;
			parameters[10].Value = model.infonv3;
			parameters[11].Value = model.infonv2;
			parameters[12].Value = model.infonv1;
			parameters[13].Value = model.infodt4;
			parameters[14].Value = model.infodt3;
			parameters[15].Value = model.infodt2;
			parameters[16].Value = model.infodt1;
			parameters[17].Value = model.infoimg1;
			parameters[18].Value = model.infoimg2;
			parameters[19].Value = model.infoimg3;
			parameters[20].Value = model.infoimg4;
			parameters[21].Value = model.dataadduserid;
			parameters[22].Value = model.datadepid;
			parameters[23].Value = model.databranchid;
			parameters[24].Value = model.datadepname;
			parameters[25].Value = model.dataaddusername;
			parameters[26].Value = model.databranchname;
			parameters[27].Value = model.dataaddtime;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.hsc_task_info model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update hsc_task_info set ");
			strSql.Append("taskid=@taskid,");
			strSql.Append("infotype=@infotype,");
			strSql.Append("infobytype1=@infobytype1,");
			strSql.Append("infotypename=@infotypename,");
			strSql.Append("infoid=@infoid,");
			strSql.Append("infofv1=@infofv1,");
			strSql.Append("infofv2=@infofv2,");
			strSql.Append("infofv3=@infofv3,");
			strSql.Append("infofv4=@infofv4,");
			strSql.Append("infonv4=@infonv4,");
			strSql.Append("infonv3=@infonv3,");
			strSql.Append("infonv2=@infonv2,");
			strSql.Append("infonv1=@infonv1,");
			strSql.Append("infodt4=@infodt4,");
			strSql.Append("infodt3=@infodt3,");
			strSql.Append("infodt2=@infodt2,");
			strSql.Append("infodt1=@infodt1,");
			strSql.Append("infoimg1=@infoimg1,");
			strSql.Append("infoimg2=@infoimg2,");
			strSql.Append("infoimg3=@infoimg3,");
			strSql.Append("infoimg4=@infoimg4,");
			strSql.Append("dataadduserid=@dataadduserid,");
			strSql.Append("datadepid=@datadepid,");
			strSql.Append("databranchid=@databranchid,");
			strSql.Append("datadepname=@datadepname,");
			strSql.Append("dataaddusername=@dataaddusername,");
			strSql.Append("databranchname=@databranchname,");
			strSql.Append("dataaddtime=@dataaddtime");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@taskid", MySqlDbType.Int64,20),
					new MySqlParameter("@infotype", MySqlDbType.Int32,11),
					new MySqlParameter("@infobytype1", MySqlDbType.Int32,11),
					new MySqlParameter("@infotypename", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoid", MySqlDbType.Int64,20),
					new MySqlParameter("@infofv1", MySqlDbType.VarChar,100),
					new MySqlParameter("@infofv2", MySqlDbType.VarChar,100),
					new MySqlParameter("@infofv3", MySqlDbType.VarChar,100),
					new MySqlParameter("@infofv4", MySqlDbType.VarChar,100),
					new MySqlParameter("@infonv4", MySqlDbType.Double),
					new MySqlParameter("@infonv3", MySqlDbType.Double),
					new MySqlParameter("@infonv2", MySqlDbType.Double),
					new MySqlParameter("@infonv1", MySqlDbType.Double),
					new MySqlParameter("@infodt4", MySqlDbType.DateTime),
					new MySqlParameter("@infodt3", MySqlDbType.DateTime),
					new MySqlParameter("@infodt2", MySqlDbType.DateTime),
					new MySqlParameter("@infodt1", MySqlDbType.DateTime),
					new MySqlParameter("@infoimg1", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoimg2", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoimg3", MySqlDbType.VarChar,50),
					new MySqlParameter("@infoimg4", MySqlDbType.VarChar,50),
					new MySqlParameter("@dataadduserid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepid", MySqlDbType.Int32,11),
					new MySqlParameter("@databranchid", MySqlDbType.Int32,11),
					new MySqlParameter("@datadepname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddusername", MySqlDbType.VarChar,100),
					new MySqlParameter("@databranchname", MySqlDbType.VarChar,100),
					new MySqlParameter("@dataaddtime", MySqlDbType.DateTime),
					new MySqlParameter("@id", MySqlDbType.Int64,20)};
			parameters[0].Value = model.taskid;
			parameters[1].Value = model.infotype;
			parameters[2].Value = model.infobytype1;
			parameters[3].Value = model.infotypename;
			parameters[4].Value = model.infoid;
			parameters[5].Value = model.infofv1;
			parameters[6].Value = model.infofv2;
			parameters[7].Value = model.infofv3;
			parameters[8].Value = model.infofv4;
			parameters[9].Value = model.infonv4;
			parameters[10].Value = model.infonv3;
			parameters[11].Value = model.infonv2;
			parameters[12].Value = model.infonv1;
			parameters[13].Value = model.infodt4;
			parameters[14].Value = model.infodt3;
			parameters[15].Value = model.infodt2;
			parameters[16].Value = model.infodt1;
			parameters[17].Value = model.infoimg1;
			parameters[18].Value = model.infoimg2;
			parameters[19].Value = model.infoimg3;
			parameters[20].Value = model.infoimg4;
			parameters[21].Value = model.dataadduserid;
			parameters[22].Value = model.datadepid;
			parameters[23].Value = model.databranchid;
			parameters[24].Value = model.datadepname;
			parameters[25].Value = model.dataaddusername;
			parameters[26].Value = model.databranchname;
			parameters[27].Value = model.dataaddtime;
			parameters[28].Value = model.id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hsc_task_info ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from hsc_task_info ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.hsc_task_info GetModel(long id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,taskid,infotype,infobytype1,infotypename,infoid,infofv1,infofv2,infofv3,infofv4,infonv4,infonv3,infonv2,infonv1,infodt4,infodt3,infodt2,infodt1,infoimg1,infoimg2,infoimg3,infoimg4,dataadduserid,datadepid,databranchid,datadepname,dataaddusername,databranchname,dataaddtime from hsc_task_info ");
			strSql.Append(" where id=@id");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int64)
			};
			parameters[0].Value = id;

			hcrainMvc.Model.hsc_task_info model=new hcrainMvc.Model.hsc_task_info();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.hsc_task_info DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.hsc_task_info model=new hcrainMvc.Model.hsc_task_info();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=long.Parse(row["id"].ToString());
				}
				if(row["taskid"]!=null && row["taskid"].ToString()!="")
				{
					model.taskid=long.Parse(row["taskid"].ToString());
				}
				if(row["infotype"]!=null && row["infotype"].ToString()!="")
				{
					model.infotype=int.Parse(row["infotype"].ToString());
				}
				if(row["infobytype1"]!=null && row["infobytype1"].ToString()!="")
				{
					model.infobytype1=int.Parse(row["infobytype1"].ToString());
				}
				if(row["infotypename"]!=null)
				{
					model.infotypename=row["infotypename"].ToString();
				}
				if(row["infoid"]!=null && row["infoid"].ToString()!="")
				{
					model.infoid=long.Parse(row["infoid"].ToString());
				}
				if(row["infofv1"]!=null)
				{
					model.infofv1=row["infofv1"].ToString();
				}
				if(row["infofv2"]!=null)
				{
					model.infofv2=row["infofv2"].ToString();
				}
				if(row["infofv3"]!=null)
				{
					model.infofv3=row["infofv3"].ToString();
				}
				if(row["infofv4"]!=null)
				{
					model.infofv4=row["infofv4"].ToString();
				}
					//model.infonv4=row["infonv4"].ToString();
					//model.infonv3=row["infonv3"].ToString();
					//model.infonv2=row["infonv2"].ToString();
					//model.infonv1=row["infonv1"].ToString();
				if(row["infodt4"]!=null && row["infodt4"].ToString()!="")
				{
					model.infodt4=DateTime.Parse(row["infodt4"].ToString());
				}
				if(row["infodt3"]!=null && row["infodt3"].ToString()!="")
				{
					model.infodt3=DateTime.Parse(row["infodt3"].ToString());
				}
				if(row["infodt2"]!=null && row["infodt2"].ToString()!="")
				{
					model.infodt2=DateTime.Parse(row["infodt2"].ToString());
				}
				if(row["infodt1"]!=null && row["infodt1"].ToString()!="")
				{
					model.infodt1=DateTime.Parse(row["infodt1"].ToString());
				}
				if(row["infoimg1"]!=null)
				{
					model.infoimg1=row["infoimg1"].ToString();
				}
				if(row["infoimg2"]!=null)
				{
					model.infoimg2=row["infoimg2"].ToString();
				}
				if(row["infoimg3"]!=null)
				{
					model.infoimg3=row["infoimg3"].ToString();
				}
				if(row["infoimg4"]!=null)
				{
					model.infoimg4=row["infoimg4"].ToString();
				}
				if(row["dataadduserid"]!=null && row["dataadduserid"].ToString()!="")
				{
					model.dataadduserid=int.Parse(row["dataadduserid"].ToString());
				}
				if(row["datadepid"]!=null && row["datadepid"].ToString()!="")
				{
					model.datadepid=int.Parse(row["datadepid"].ToString());
				}
				if(row["databranchid"]!=null && row["databranchid"].ToString()!="")
				{
					model.databranchid=int.Parse(row["databranchid"].ToString());
				}
				if(row["datadepname"]!=null)
				{
					model.datadepname=row["datadepname"].ToString();
				}
				if(row["dataaddusername"]!=null)
				{
					model.dataaddusername=row["dataaddusername"].ToString();
				}
				if(row["databranchname"]!=null)
				{
					model.databranchname=row["databranchname"].ToString();
				}
				if(row["dataaddtime"]!=null && row["dataaddtime"].ToString()!="")
				{
					model.dataaddtime=DateTime.Parse(row["dataaddtime"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,taskid,infotype,infobytype1,infotypename,infoid,infofv1,infofv2,infofv3,infofv4,infonv4,infonv3,infonv2,infonv1,infodt4,infodt3,infodt2,infodt1,infoimg1,infoimg2,infoimg3,infoimg4,dataadduserid,datadepid,databranchid,datadepname,dataaddusername,databranchname,dataaddtime ");
			strSql.Append(" FROM hsc_task_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM hsc_task_info ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from hsc_task_info T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "hsc_task_info";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

